package com.leihao.product.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.leihao.common.core.domain.R;
import com.leihao.product.domian.MemberPrice;
import com.leihao.product.domian.ProductFullReduction;
import com.leihao.product.domian.ProductLadder;
import com.leihao.product.domian.Subject;
import com.leihao.product.domian.listRequest.ProductListRequest;
import com.leihao.product.domian.vo.ProductVo;
import com.leihao.product.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("product")
@Api(tags = "商品管理")
public class ProductController {

    @Autowired
    private ProductService productService;

    /**
     * 条件查询商品列表
     */
    @PostMapping("/findList")
    @ApiOperation(value = "获取参数配置列表")
    public R<PageInfo<ProductVo>> findList(@RequestBody ProductListRequest productListRequest)
    {
        PageInfo<ProductVo> list = productService.findList(productListRequest);
        return R.ok(list);
    }

    /**
     * 修改商品
     * @param productVo
     * @return
     */
   @PutMapping("update")
    public R update(@RequestBody ProductVo productVo)
    {
        productService.update(productVo);
        return R.ok(null,"修改成功");
    }
    /**
     * 修改商品状态
     * @param productVo
     * @return
     */
   @PutMapping("updateStatus")
    public R updateStatus(@RequestBody ProductVo productVo)
    {
        productService.updateStatus(productVo);
        return R.ok(null,"修改成功");
    }
    /**
     * 添加商品
     * @param productVo
     * @return
     */
   @PostMapping("add")
    public R add(@RequestBody ProductVo productVo)
    {
        productService.add(productVo);
//        productService.update(productVo);
        return R.ok(null,"添加成功");
    }

    /**
     * 删除商品
     * @return
     */
   @DeleteMapping("delete/{productId}")
    public R delete(@PathVariable Integer productId)
    {
        productService.delete(productId);
        return R.ok(null,"删除成功");
    }


    /**
     * 查询服务中间表
     * @param productId
     * @return
     */
    @GetMapping("findByServiceGuaranteemidden/{productId}")
    public R<Integer[]> findByServiceGuaranteemidden(@PathVariable Integer productId){
        return R.ok(productService.findByServiceGuaranteemidden(productId));
    }

    /**
     * 查询阶梯价格
     * @param productId
     * @return
     */
    @GetMapping("findByLadderList/{productId}")
    public R<List<ProductLadder>> findByLadderList(@PathVariable Integer productId){
        return R.ok(productService.findByLadderList(productId));
    }

    /**
     * 查询会员价格
     * @param productId
     * @return
     */
    @GetMapping("findByMemberPriceList/{productId}")
    public R<List<MemberPrice>> findByMemberPriceList(@PathVariable Integer productId){
        return R.ok(productService.findByMemberPriceList(productId));
    }
    /**
     * 查询满减
     * @param productId
     * @return
     */
    @GetMapping("findByFullReductionList/{productId}")
    public R<List<ProductFullReduction>> findByFullReductionList(@PathVariable Integer productId){
        return R.ok(productService.findByFullReductionList(productId));
    }

    /**
     * 查询专题中间表
     * @param productId
     * @return
     */
    @GetMapping("findBySubjectmidden/{productId}")
    public R<Integer[]> findBySubjectmidden(@PathVariable Integer productId){
        return R.ok(productService.findBySubjectmidden(productId));
    }
    /**
     * 查询优选中间表
     * @param productId
     * @return
     */
    @GetMapping("findByPreferenceMidden/{productId}")
    public R<Integer[]> findByPreferenceMidden(@PathVariable Integer productId){
        return R.ok(productService.findByPreferenceMidden(productId));
    }

}
